package com.mallcloud.mall.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.app.api.entity.dto.AppProductSearchDTO;
import com.mallcloud.mall.app.api.entity.vo.AppProductSearchShopVO;
import com.mallcloud.mall.app.api.entity.vo.AppProductSearchSpuVO;
import com.mallcloud.mall.app.service.AppProductService;
import com.mallcloud.mall.common.core.constant.enums.mall.MallCommonEnum;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.product.api.entity.HotSearchModel;
import com.mallcloud.mall.product.service.HotSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "商品分类管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/productSearch")
public class AppProductSearchController {
    private final AppProductService appProductService;
    private final HotSearchService hotSearchService;

    @ApiOperation("第三级分类分页查询店铺与商品")
    @GetMapping("/pageShop")
    public R<IPage<AppProductSearchShopVO>> searchPageShop(Page page, AppProductSearchDTO dto) {
        return R.ok(appProductService.pageSearchShop(page, dto));
    }

    @ApiOperation("第三级分类分页查询商品")
    @GetMapping("/pageSpu")
    public R<IPage<AppProductSearchSpuVO>> searchPageSpu(Page page, AppProductSearchDTO dto) {
        return R.ok(appProductService.pageSearchSpu(page, dto));
    }

    @ApiOperation("热门搜索")
    @GetMapping("/keyword")
    public R<List<HotSearchModel>> hotKeywords() {
        return R.ok(hotSearchService.page(new Page<>(1, 5), Wrappers.<HotSearchModel>lambdaQuery()
                .eq(HotSearchModel::getStatus, MallCommonEnum.StatusEnum.Y.getCode())
                .orderByDesc(HotSearchModel::getSortOrder)
        ).getRecords());
    }
}
